package com.maimao.auth.client.fallback;

import com.maimao.auth.client.SysUserClient;
import com.maimao.core.enums.RespCode;
import com.maimao.core.model.resp.Result;
import com.maimao.model.user.sys.vo.Permissions;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author MaoLin Wang
 * @date 2020/11/30 10:03 下午
 */
@Component
@Slf4j
public class SysUserFallBackFactory implements FallbackFactory<SysUserClient> {
    @Override
    public SysUserClient create(Throwable cause) {
        String errorMsg = cause.getMessage() == null ? "" : cause.getMessage();

        return new SysUserClient() {
            @Override
            public String toString() {
                return "$classname{}";
            }

            @Override
            public Result<Permissions> getPermissionByUserName(String username) {
                log.error("调用[UserClient-getPermission({})]出错 :{}", username, errorMsg);
                return Result.fail(RespCode.FAIL, errorMsg);
            }

        };
    }
}
